X-Git-Url: https://git.r.bdr.sh/rbdr/captura/blobdiff_plain/7ee43fb83799abb89a69cfcd4e2146dd4eaa5045..4b9281467f2794aa096929d665f5f9536152411c:/Captura/Core%20Extensions/CVImageBuffer%20cgImage.swift/rbdr/captura/blobdiff_plain/7ee43fb83799abb89a69cfcd4e2146dd4eaa5045..4b9281467f2794aa096929d665f5f9536152411c:/Captura/Core%20Extensions/CVImageBuffer+cgImage.swift diff --git a/Captura/Core Extensions/CVImageBuffer+cgImage.swift b/Captura/Core Extensions/CVImageBuffer+cgImage.swift index f8958f2..3f59b8e 100644 --- a/Captura/Core Extensions/CVImageBuffer+cgImage.swift +++ b/Captura/Core Extensions/CVImageBuffer+cgImage.swift @@ -3,10 +3,19 @@ import ReplayKit extension CVImageBuffer { - static let sharedContext = CIContext() + private static let contextQueue = DispatchQueue(label: "com.example.contextQueue") + static let sharedContext: CIContext = { + return CIContext() + }() var cgImage: CGImage? { - let ciImage = CIImage(cvImageBuffer: self) - return CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(self), height: CVPixelBufferGetHeight(self))) + var result: CGImage? + CVImageBuffer.contextQueue.sync { + let ciImage = CIImage(cvImageBuffer: self) + let width = CVPixelBufferGetWidth(self) + let height = CVPixelBufferGetHeight(self) + result = CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height)) + } + return result } }